/*
 * Copyright (c) 1999-2009 InfoReach, Inc. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * InfoReach ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with InfoReach.
 *
 * CopyrightVersion 2.0
 *
 */
package com.inforeach.util.string;

import java.util.List;
import java.util.ListIterator;

/**
 * 
 * @author dmytros
 */
public class ChainedStringTransformer implements IStringTransformer
{
    private final List<IStringTransformer> transformers_;

    public ChainedStringTransformer(List<IStringTransformer> transformers)
    {
        transformers_ = transformers;
    }

    @Override
    public String forward(String str)
    {
        ListIterator<IStringTransformer> iter = transformers_.listIterator(0);
        while (iter.hasNext())
        {
            IStringTransformer transformer = iter.next();
            str = transformer.forward(str);
        }
        return str;
    }

    @Override
    public String reverse(String str)
    {
        ListIterator<IStringTransformer> iter = transformers_.listIterator(transformers_.size());
        while (iter.hasPrevious())
        {
            IStringTransformer transformer = iter.previous();
            str = transformer.reverse(str);
        }
        return str;
    }

}
